const express = require("express");

const cookieParser = require("cookie-parser");

const app = express();
app.use(cookieParser());

//设置cookie
app.get("/set-cookie", (req, res) => {
  res.cookie("name", "zhangsan"); //此cookie会在浏览器关闭的时候销毁
  //maxAge是设置生命周期  单位是毫秒  60*1000 就是60s 60s后此cookie过期
  res.cookie("name", "zhangsan", { maxAge: 60 * 1000 });

  res.send("set-cookie");
});

//删除cookie
app.get("/remove-cookie", (req, res) => {
  res.clearCookie("name"); //删除 cookie  name
  res.send("remove-cookie");
});

//获取cookie  使用cookie-parser 中间件
app.get("/get-cookie", (req, res) => {
  console.log(req.cookies); //
  res.send("get-cookie");
});

app.listen(3000);
